package com.tom;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class MemberController
 */
public class Order01Controller extends HttpServlet {
        private static final long serialVersionUID = 1L;
        private static final String LIST_ORDER01 = "listOrder01.jsp";
        private static final String ADD_ORDER01 = "order01.jsp";
        private static final String EDIT_ORDER01 = "order01_edit.jsp";

        private Order01DAO dao;

        /**
         * @see HttpServlet#HttpServlet()
         */
        public Order01Controller() {
                super();
                dao = new Order01DAO();
        }

        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doGet(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {

        	doPost(request, response);
//        		
        }


        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doPost(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
        	request.setCharacterEncoding("UTF-8");
            String forward = LIST_ORDER01;
            String action = request.getParameter("action");
            if (action == null) {
                    forward = LIST_ORDER01;
            } else {
                    if (action.equalsIgnoreCase("listorder01")) {
                            forward = LIST_ORDER01;
                    }
                    if (action.equalsIgnoreCase("addorder01")) {
                            if (request.getParameter("ord01_num") != null) {
                                    // save
                                    String ord01_num = request.getParameter("ord01_num");
                                    String ord01_id = request.getParameter("ord01_id");
                                    String ord01_namec = request.getParameter("ord01_namec");
                                    String ord01_namea = request.getParameter("ord01_namea");
                                    String ord01_area = request.getParameter("ord01_area");
                                    String ord01_telephone = request.getParameter("ord01_telephone");
                                    String ord01_telephone_p = request.getParameter("ord01_telephone_p");
                                    String ord01_mobil = request.getParameter("ord01_mobil");
                                    String ord01_date1 = request.getParameter("ord01_date1");
                                    String ord01_date2 = request.getParameter("ord01_date2");                      
                                    String ord01_pay = request.getParameter("ord01_pay");
                                    String ord01_sales = request.getParameter("ord01_sales");
                                    String ord01_yn = request.getParameter("ord01_yn");
                                    String ord01_date3 = request.getParameter("ord01_date3");
                                    String ord01_memo = request.getParameter("ord01_memo");                                       
                                    Order01 o = new Order01(ord01_num, ord01_id, ord01_namec, ord01_namea, ord01_area, ord01_telephone, ord01_telephone_p, ord01_mobil, ord01_date1, ord01_date2,ord01_pay, ord01_sales, ord01_yn, ord01_date3, ord01_memo);
                                    dao.add(o);
                                    forward = LIST_ORDER01;
                            } else {
                                    forward = ADD_ORDER01;
                            }
                    }
                    if (action.equalsIgnoreCase("edit")) {
                    	String name = request.getParameter("ord01_num");
                            Order01 o = dao.getOrder01ById(name);
                            request.setAttribute("o", o);
                            forward = EDIT_ORDER01;
                    }
            }
            List<Order01> order01s = dao.getAll();
            request.setAttribute("order01s", order01s);
            RequestDispatcher dispatcher = request
                            .getRequestDispatcher(forward);
            dispatcher.forward(request, response);
//        		request.setCharacterEncoding("UTF-8");
//                String action = request.getParameter("action");
//                if (action.equalsIgnoreCase("edit")) {
//                        Order01 o = new Order01(request.getParameter("ord01_num"),
//                        		request.getParameter("ord01_id"),
//                        		request.getParameter("ord01_namec"),
//                        		request.getParameter("ord01_namea"),
//                        		request.getParameter("ord01_area"),
//                        		request.getParameter("ord01_telephone"),
//                        		request.getParameter("ord01_telephone_p"),
//                        		request.getParameter("ord01_mobil"),
//                        		request.getParameter("ord01_date1"),
//                        		request.getParameter("ord01_date2"),                       		
//                        		request.getParameter("ord01_pay"),
//                        		request.getParameter("ord01_sales"),
//                        		request.getParameter("ord01_yn"),
//                        		request.getParameter("ord01_date3"),
//                        		request.getParameter("ord01_memo"));
//                        dao.update(o);
//                        List<Order01> order01s = dao.getAll();
//                        request.setAttribute("order01s", order01s);
//                        RequestDispatcher dispatcher = request
//                                        .getRequestDispatcher(LIST_ORDER01);
//                        dispatcher.forward(request, response);
//                }
        }


}